import httpStatusNavigateTo from './httpStatusNavigateTo';


export function Login(){
	const store = require('@/store/index').default;
	const {wxLogin} = require('@/api/system/SysUserInfo');
	const platform = uni.getSystemInfoSync().platform;
	uni.getProvider({
		service:"oauth",
		success: (res) => {
			if(~res.provider.indexOf('weixin')){
				uni.login({
					provider:"weixin",
					success: (loginRes) => {
						uni.getUserInfo({
							success: (resInfo) => {
								wxLogin({
									jsCode:loginRes.code,
									encryptedData:resInfo.encryptedData,
									iv:resInfo.iv
								}).then(response => {
									const code = response.code;
									if (code !== 200){
										httpStatusNavigateTo(code);
										return;
									}
									store.commit('updateUserInfo',response.data);
								});
							},
							fail: (res) => {
								console.log(res);
							}
						})
					},
					complete: (error) => {
						console.log(error);
					}
				})
			}
		},
		complete: (error) => {
			console.log(error);
		}
		
	})
}


export function Logout(){
	const store = require('@/store/index').default;
	store.commit('logout');
	uni.removeStorageSync('Set-Cookie');
}